package tests;

import static org.junit.Assert.assertTrue;
import gestioneDatabase.Post.AllPostsRetriever;
import gestioneDatabase.Post.PostsManager;

import java.util.ArrayList;

import models.Post;
import models.User;

import org.junit.Before;
import org.junit.Test;

public class TestPost {

	PostsManager testPostManager = PostsManager.getManager();
	User testUser = null;
	Post testPost = null;
	Post testRespone = null;
	AllPostsRetriever testPostRetriver = null;
	
	@Before
	public void createNewTestPost() {
		testUser = new User("test-user");
		testPost = new Post(testUser);
		testPost.setId(3);
		testRespone = new Post(new User("Responder"));
		testPostRetriver = new AllPostsRetriever();		
	}

	@Test
	public void testNewPostWithAuthor() {
		new Post(new User("user1"));
	}
	
	@Test
	public void testGetID() {
		assertTrue(testPost.getId()==3);
	}

	@Test
	public void testGetAuthor() {
		assertTrue(testPost.getAuthor().equals(testUser));
	}

	@Test
	public void testGetTitle() {
		testPost.setTitle("test-title");
		assertTrue(testPost.getTitle().equals("test-title"));
	}

	@Test
	public void testGetContent() {
		testPost.setContent("test-content");
		assertTrue(testPost.getContent().equals("test-content"));
	}
	
	@Test
	public void testAddResponse(){
		testPost.addResponse(testRespone);
		assertTrue(testPost.getResponses().get(0).getAuthor().getFullName().equals("Responder"));
	}
	
	@Test
	public void testGetResponses(){
		testPost.addResponse(testRespone);
		ArrayList<Post> testResponses = testPost.getResponses();
		assertTrue(testResponses.size() == 1 && testResponses.get(0).getAuthor().getFullName().equals("Responder"));
	}
	
	@Test
	public void testGetStyle(){
		testPost.setStyle("mint");
		assertTrue(testPost.getStyle().equals("mint"));
	}

}
